#!/bin/sh
############################
# auther	: sgxiao
# date		: 2009-01-18
# filename	: average_return.sh
# version	: 0.1
# history
# sgxiao	0.1	build up
#
############################


for file in 1_50 1_150 1_200 2_200 5_150 10_200
do
#####


startYear=1995
endYear=2007

while [ ${startYear} -le ${endYear} ]
do
####
	echo "#!/bin/sh" > sumup.sh
	cat $((startYear-1)).array.top50 >> sumup.sh
	echo "startYear=${startYear}" >> sumup.sh
	echo "file=\"${file}\"" >> sumup.sh
	cat sumup.tample.1.sh >> sumup.sh
	filenames=`wc -l ${startYear-1}.array.top50 | awk '{print $1}'`
##
	echo "i=0
while [ \$i -le $((filenames-1)) ]" >> sumup.sh
##
	cat sumup.tample.2.sh >> sumup.sh

	chmod a+x *.sh
	./sumup.sh

	startYear=$((startYear+1))
####
done

	cat *.${file}.average.return > total.${file}.average.return
	rm [0-9][0-9][0-9][0-9].${file}.average.return

	rm *.temp.return
#####
done

./recaculate.sh


#mv total* ../
#rm *.whole.return
#mv *.whole.return ../
mv *.array.top50 ../
